package com.zepher.tourism.config;


import com.zepher.tourism.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Spring MVC Web 配置类，用于注册拦截器并设置拦截规则。
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 注入 TokenInterceptor 拦截器，用于处理请求中的 token 验证。
     */
    @Autowired
    private TokenInterceptor tokenInterceptor;

    /**
     * 添加自定义拦截器，对请求进行统一处理。
     * @param registry 拦截器注册器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                //拦截所有请求
                .addPathPatterns("/**")
                //排除请求
                .excludePathPatterns("/file/**","/video/**","/img/**","/login","/common/**","/user/setUserAvatar/**"
                        ,"/user/getEmailReg/**","/user/forgetPassword/**","/user/saveUser/**");
    }
}
